package com.edu.web.servlet;



import com.edu.bean.User;
import com.edu.service.UserService;
import com.edu.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        System.out.println("进入");
        String userName=req.getParameter("username");
        String userPass=req.getParameter("password");
        String realName=req.getParameter("nickname");
        UserService userRegisterService=new UserServiceImpl();
        User user=new User();
        user.setUsername(userName);
        user.setUserpass(userPass);
        user.setRealName(realName);
        int num=userRegisterService.registerService(user);
        if (num==1){
            System.out.println("注册成功");
        }else{
            System.out.println("失败");
        }
        req.getSession().setAttribute("registered", true);
        resp.sendRedirect("login.jsp");
    }
}
